package com.example.day2.busi.my;

import android.content.Intent;
import android.view.View;

import androidx.annotation.NonNull;
import androidx.fragment.app.Fragment;

import com.blankj.utilcode.util.SPUtils;
import com.bumptech.glide.Glide;
import com.example.day2.R;
import com.example.day2.adapter.FragmentAdapter;
import com.example.day2.databinding.FragmentMyBinding;
import com.example.day2.mvvm.base.BaseViewFragment;
import com.google.android.material.tabs.TabLayout;
import com.google.android.material.tabs.TabLayoutMediator;

import java.util.ArrayList;

public class MyFragment extends BaseViewFragment<FragmentMyBinding> {
    @Override
    public void initView() {
        String icon = SPUtils.getInstance().getString("icon");
        Glide.with(getActivity()).load(icon).circleCrop().into(binding.iv);
        String nickname = SPUtils.getInstance().getString("nickname");
        binding.tv.setText(nickname);

        ArrayList<String> list = new ArrayList<>();
        list.add("收藏");
        list.add("点赞");

        ArrayList<Fragment> list1 = new ArrayList<>();
        list1.add(new StoreFragment());
        list1.add(new LiveFragment());

        FragmentAdapter fragmentAdapter = new FragmentAdapter(getActivity(),list1);
        binding.vp2.setAdapter(fragmentAdapter);
        //tablayout与vp结合
        new TabLayoutMediator(binding.t1, binding.vp2, new TabLayoutMediator.TabConfigurationStrategy() {
            @Override
            public void onConfigureTab(@NonNull TabLayout.Tab tab, int position) {
                tab.setText(list.get(position));
            }
        }).attach();
        binding.iv2.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                startActivity(new Intent(getContext(),SettingActivity.class));
            }
        });

    }

    @Override
    public void initData() {

    }

    @Override
    public int bindLayoutId() {
        return R.layout.fragment_my;
    }
}
